-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New evmone API: StateView & StateDiff #802
Conversation
0f92b8a
to
af88125
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #802 +/- ##
==========================================
+ Coverage 94.21% 94.23% +0.01%
==========================================
Files 153 155 +2
Lines 15934 15968 +34
==========================================
+ Hits 15012 15047 +35
+ Misses 922 921 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
1ea121a
to
3f608b1
Compare
d77ecd8
to
83342e2
Compare
0028573
to
1bab196
Compare
e4e3eb4
to
838a5cf
Compare
test/state/host.cpp
Outdated
} | ||
|
||
bytes32 Host::get_code_hash(const address& addr) const noexcept | ||
{ | ||
// TODO: Cache code hash. It will be needed also to compute the MPT hash. | ||
const auto raw_code = m_state.get_code(addr); | ||
if (is_eof_container(raw_code)) | ||
return keccak256(raw_code.substr(0, 2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is probably good idea to handle EOF ext code and possible code hash caching up front.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Proposed in #1035.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to wrap head around this, but here some early comments
@@ -92,37 +89,45 @@ bytes_view extcode(bytes_view code) noexcept | |||
/// as defined in the [EIP-7610](https://eips.ethereum.org/EIPS/eip-7610). | |||
[[nodiscard]] bool is_create_collision(const Account& acc) noexcept | |||
{ | |||
if (acc.nonce != 0 || !acc.code.empty()) | |||
// TODO: This requires much more testing: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better file as issue(s)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test/state/state.hpp
Outdated
@@ -62,14 +63,16 @@ class State | |||
std::variant<JournalBalanceChange, JournalTouched, JournalStorageChange, JournalNonceBump, | |||
JournalCreate, JournalTransientStorageChange, JournalDestruct, JournalAccessAccount>; | |||
|
|||
const StateView* m_cold = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment pls what this means, making sure to answer its relation to the notion of cold/warm storage (access lists and whatnot). I kinda know but would appreciate the comment to make sure and make it easier to digest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would maybe rename this and m_accounts
: m_initial_state
and m_modified_accounts
maybe.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "initial" and "modified" sounds nice. How about just m_initial
and m_modified
?
Wrap the usage of the state transition API from the `evmone::state` for tests so that the new API in `evmone::test` only exposes `TestState` and hides `state::State`. This isolates usage of the `evmone::state` to lower the disturbance caused by API modifications, e.g. in #802.
28caf35
to
a7cac6e
Compare
Wrap the usage of the state transition API from the `evmone::state` for tests so that the new API in `evmone::test` only exposes `TestState` and hides `state::State`. This isolates usage of the `evmone::state` to lower the disturbance caused by API modifications, e.g. in #802.
a7cac6e
to
5ef5009
Compare
Wrap the usage of the state transition API from the `evmone::state` for tests so that the new API in `evmone::test` only exposes `TestState` and hides `state::State`. This isolates usage of the `evmone::state` to lower the disturbance caused by API modifications, e.g. in #802.
5ef5009
to
65c7d8e
Compare
4c5c323
to
d69bc4c
Compare
if (std::ranges::any_of( | ||
acc.storage, [](auto& e) noexcept { return !is_zero(e.second.current); })) | ||
if (acc.code_hash != Account::EMPTY_CODE_HASH) | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not covered by any tests, so more work for #1037. Should I remove/shorten the TODO comments here?
8a8e576
to
da4cd30
Compare
// TODO(clang): In old Clang emplace_back without Account doesn't compile. | ||
// NOLINTNEXTLINE(modernize-use-emplace) | ||
auto& a = diff.modified_accounts.emplace_back(StateDiff::Entry{addr, m.nonce, m.balance}); | ||
if (m.just_created && !m.code.empty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note for the future: in 7702 the code may change 😱 (when resetting existing delegation to another account)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be doable.
Why |
Introduce the type `StateDiff` to represent a set of modifications to the State. Implement the procedure to collect the set of changes out of an intra state object.
Implement `TestState::appy(StateDiff)` procedure to apply state changes back to the state.
da4cd30
to
bd366dc
Compare
This is the interface a user of the API has to implement (similarly to EVMC's Host). In evmone the user is |
Return `StateDiff` out of: - `state::transition()` (as a subobject of `TransactionReceipt`) - `state::system_call()` - `state::finalize()`
Introduce `StateView` interface as a way to read the initial/cold State.
Implement `StateView` interface in `TestState`. This will be used later.
@@ -409,9 +415,7 @@ evmc::Result Host::execute_message(const evmc_message& msg) noexcept | |||
if (is_precompile(m_rev, msg.code_address)) | |||
return call_precompile(m_rev, msg); | |||
|
|||
// In case msg.recipient == msg.code_address, this is the second lookup of the same address. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment is still true I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of true, but now this is the State::get_code()
API issue: how to combine local account lookup with code lookup.
bd366dc
to
889d23f
Compare
Modify the `State` to require `StateView` interface as a parameter and use it to read the initial state values. This drops `TestState` dependency on `State`.
889d23f
to
3350cd7
Compare
A step towards of the new API for evmone. It uses the test runners as users and modifies the
State
API fromstate.h
.StateView
interface with (simpler thanState
) representation of the State.transition()
) takes theStateView
and producesStateDiff
.StateDiff
to itsStateView
implementation.The current state diff building is based on visiting the intra state cache of accounts loaded from initial state. This approach is relatively simple but has some false positives and may not be efficient.